var vm = new Vue({
    el: "#app",
    data: {
        rtype: 0,
        my_text: '', //反馈文字
        img_src: '',
        img_id: '',
        ismask: false
    },
    methods: {
        // 提交
        submitBtn: function() {
            var that = this;
            if (that.my_text.length < 10) {
                vant.Toast('内容不得少于10个字');
                return;
            }
            var value = {
                title: Number(that.rtype),
                content: that.my_text
            };
            if (that.img_id != '') {
                value.image = that.img_id;
            };
            that.ismask = true;
            $.post(app.webUrl + '/basic/api_feedback/send', value, cb).fail(function(err) {
                console.log(err);
                that.ismask = false;
            });

            function cb(ret) {
                that.ismask = false;
                if (ret.code == '1') {
                    vant.Toast('提交成功');
                    // 返回上一个页面
                    setTimeout(function() {
                        $('header img').trigger('click');
                    }, 1000)
                }
            }
        },
        // 选择反馈的类型
        chooseItem: function(i) {
            this.rtype = i;
        },

        // 上传图片
        upload: function() {
            var that = this;
            var dom = $('#inputBox').get(0);
            var file = dom.files[0];
            var formData = new FormData();
            formData.append('file', file);
            formData.append('dir', 'images');
            $.ajax({
                type: "post",
                url: app.webUrl + '/index/plugin/execute/_plugin/WxSdk/_controller/Api/_action/file',
                data: formData,
                contentType: false,
                processData: false,
                success: function(ret) {
                    // console.log(ret);
                    ret = JSON.parse(ret);
                    if (ret.code == 1) {
                        that.img_src = ret.path;
                        that.img_id = ret.id;
                    }
                }
            });
        }
    },
});

// 设置选中的状态